<template>
    <div class="newsInfo-container">
        <h3 class="title">{{ newsInfo.title }}</h3>
        <p class="subtitle">
            <span>发表时间：{{ newsInfo.add_time | dateFormat }}</span>
            <span>点击：{{ newsInfo.click }}次</span>
        </p>

        <hr>

        <div class="content" v-html="newsInfo.content"></div>

        <!-- 评论子组件 -->
        <comment :id="id"></comment>

    </div>
</template>

<script>
    import { Toast } from 'mint-ui'
    import Comment from '../../../../components/content/comment/comment.vue'

    export default {
        name: "",
        data(){
            return {
                id: this.$route.params.id,
                newsInfo: {}
            }
        },
        created(){
            this.getNewsInfo()
        },
        methods: {
            getNewsInfo(){
                this.$http.get('static/data/newsInfo.json').then(res => {
                    if(res.body.status === 0){
                        this.newsInfo = res.body.message.find(item => item.id === parseInt(this.id))
                    }else{
                        Toast('获取新闻失败')
                    }
                })
            }
        },
        components: {
            Comment
        }
    }
</script>

<style lang="less">
.newsInfo-container{
    padding: 0 4px;
    .title{
        text-align: center;
        font-size: 16px;
        margin: 15px 0;
        color: red;
    }
    .subtitle{
        font-size: 13px;
        color: #2aabd2;
        display: flex;
        justify-content: space-between;
    }
    .content{
        img{
            display: block;
            width: 100%;
        }
    }
}
</style>